#!/bin/sh /etc/rc.common
. /usr/share/libubox/jshn.sh
. /lib/functions.sh

START=96
USE_PROCD=1
OAFD_BIN="/usr/bin/oafd"
FEATURE_FILE="/tmp/feature.cfg"
CLASS_FILE="/tmp/app_class.txt"
service_triggers()
{
	procd_add_reload_trigger "appfilter"
}

stop_service(){
	killall -9 oafd
	rmmod oaf
}

start_service(){
	local update
	rm $FEATURE_FILE
	update=`uci get appfilter.feature.update`
	if [ x"1" == x"$update" ];then
		ln -s /etc/appfilter/feature.cfg $FEATURE_FILE
	else
		uci get luci.languages.zh_cn >/dev/null 2>&1
		if [ $? -eq 0 ];then
			test -f $FEATURE_FILE && rm $FEATURE_FILE
			ln -s /etc/appfilter/feature_cn.cfg $FEATURE_FILE
		else
			ln -s /etc/appfilter/feature_en.cfg $FEATURE_FILE
		fi
	fi
	gen_class.sh /tmp/feature.cfg
	insmod oaf
	/usr/bin/oaf_rule reload
	procd_open_instance
	procd_set_param respawn 60 5 5
	procd_set_param stderr 1
	procd_set_param command "$OAFD_BIN"
	procd_close_instance
}
